import { API } from '../helpers/axios'

const buildUrl = endPoint => `/api/v1/${endPoint}${window.location.search}`

export default {
  get() {
    return API.get(buildUrl('widget/contacts'))
  },
  update(userObject) {
    return API.patch(buildUrl('widget/contacts'), userObject)
  },
  setUser(identifier, userObject) {
    return API.patch(buildUrl('widget/contacts/setUser'), {
      identifier,
      ...userObject
    })
  },
  setCustomAttributes(customAttributes = {}) {
    return API.patch(buildUrl('widget/contacts'), {
      customAttributes: customAttributes
    })
  },
  deleteCustomAttribute(customAttribute) {
    return API.post(buildUrl('widget/contacts/destroyCustomAttributes'), {
      customAttributes: [customAttribute]
    })
  }
}
